import { AIPropertyDescriptor, IField } from "../AIProperty";
import { Field } from "./Field";

export class AssetField extends Field implements IField {
    create(o: AIPropertyDescriptor, data: any) {
        let p = this._create(o, 'Asset', data, '');
        let val = this._panel.getChild("value") as IEditor.ResourceInput;
        if (o.assetTypeFilter) {
            val.typeFilter = [IEditor.AssetType[o.assetTypeFilter]];
        }
        val.on("submit", this._changeHandle, this);
        return p;
    }
    protected _changeHandle(e: gui.Event) {
        let txt = (e.target as any).text;
        this.data[this.o.name] = txt;
        this._checkChange();
    }
}